********************************************************************************
** 	TITLE: f15_cfs_effects_work_exp.do

**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Table XV: Effects of High IGNITE Exposure: Custody Staff Views on Own Work
**		Experience
********************************************************************************
		set sortseed 13

use "$output_data/IGNITE_corrections_survey_clean.dta", clear

gen d_female = 1-d_male

gen treatment = d_contact
gen post = !d_work_preignite
la var post "Started Work after IGNITE"
la var d_postcovid "Started Work after Covid"
la var d_female "Female"

local covs  d_female d_black  d_age_1 d_age_2 d_age_3 d_age_4 post d_postcovid

gen mi_any = 0
foreach var in `covs'{
	replace `var' = -99 if `var' == .
	replace mi_any = 1 if `var' == -99 
}

keep if !mi_any

/***********************************************
regressions
***********************************************/

local work_exp work_experience_1_t work_experience_2_t work_experience_3_t
local d_work_exp d_work_experience_1 d_work_experience_2 d_work_experience_3 

la var d_work_experience_1 "Satisified with Own Job"
la var d_work_experience_2 "Benefit Package is Competitive"
la var d_work_experience_3 "Pay is High Enough"

* F test
reg treatment `covs'  i.survey_month
local N = e(N)
di `N'

//d_work_exp

		cap file close fh
		cap erase "$tables/correctional_survey_effects_d_work_exp.tex"
		file open fh using "$tables/correctional_survey_effects_d_work_exp.tex", write replace
		
		foreach v in `d_work_exp' {
			reg `v' d_contact i.survey_month, r
			local b_`v' : di %8.3f _b[d_contact]
			local b_`v' = subinstr("`b_`v''"," ","",.)
			
			
			lincom d_contact
			local se_`v': di %8.3f r(se)
			local se_`v' = subinstr("(`se_`v'')"," ","",.)
			
			local p = r(p)
			local sig_`v' " "
			if `p'<0.1{
				local sig_`v' "$ ^{*} $ "
			}
			if `p'<0.05{
				local sig_`v' "$ ^{**} $ "
			}
			if `p'<0.01{
				local sig_`v' "$ ^{***} $ "
			}
			
			local lab_`v': var label `v'
			local b_`v' =  "`b_`v''`sig_`v''"
			su `v' if e(sample)&!d_contact, de
			local raw_mean = r(mean)
			local raw_mean: di %8.3f `raw_mean'
			local m_`v' = subinstr("`raw_mean'"," ","",.)
			
			file write fh ///
				"`lab_`v'' & `b_`v''& `se_`v''& `m_`v'' &	`N' \\ "_n
		}
		
		reg d_contact `d_work_exp'  i.survey_month, r
		testparm `d_work_exp'
		
		local f_stat : di %8.3f r(F)
		local f_stat_d_work_exp = subinstr("`f_stat'"," ","",.)

		local f_p : di %8.3f r(p)
		local sig_`v' " "
		if `f_p'<0.1{
		local sig_`v' "$ ^{*} $ "
		}
		if `f_p'<0.05{
			local sig_`v' "$ ^{**} $ "
		}
		if `f_p'<0.01{
			local sig_`v' "$ ^{***} $ "
		}
		local f_p_d_work_exp = subinstr("`f_p'"," ","",.)
		
		file write fh ///
			"\vspace{-.4cm} \\ " _n /// 
			"\cline{2-5} \vspace{-.4cm} \\ " _n /// 
			" \emph{F}-Test for Joint Test [\emph{p}-Value] & `f_stat_d_work_exp'`sig_`v'' & [`f_p_d_work_exp']&   &	`N' \\ "_n
			
		cap file close fh
		macro drop fh